// import path from "path";
// import fs from "fs";
// import { NextFunction, Request, Response, Router } from "express";
import { Router } from "express";
// import Crawler from "./utils/crawler";
// import WalkerAnalyzer from "./utils/walkerAnalyzer";
// import { getResponseData } from "./utils/util";

// const checkLogin = (req: Request, res: Response, next: NextFunction) => {
//   const isLogin = req.session ? req.session.login : false;
//   if (isLogin) {
//     next();
//   } else {
//     res.json(getResponseData(null, "Login first"));
//   }
// };

const router = Router();

// router.get("/", (req, res) => {
//   const isLogin = req.session ? req.session.login : false;
//   if (isLogin) {
//     res.send(`
//     <html>
//       <body>
//         <a href='/showdata'>Show</a>
//         <a href='/getdata'>Get</a>
//         <a href='/logout'>Exit</a>
//       </body>
//     </html>
//     `);
//   } else {
//     res.send(`
//     <html>
//       <body>
//         <form method="post" action="/login">
//           <input type="password" name="password"/>
//           <button>summit</button>
//         </form>
//       </body>
//     </html>
//     `);
//   }
// });

// router.get("/logout", (req, res) => {
//   if (req.session) {
//     req.session.login = undefined;
//   }
//   res.json(getResponseData(true));
// });

// router.post("/login", (req, res) => {
//   const { password } = req.body;
//   const isLogin = req.session ? req.session.login : false;
//   if (isLogin) {
//     res.json(getResponseData(false, "Already login!"));
//   } else {
//     if (password === "123" && req.session) {
//       req.session.login = true;
//       res.json(getResponseData(true));
//     } else {
//       res.json(getResponseData(false, "Login failed!"));
//     }
//   }
// });

// router.get("/getdata", checkLogin, (req, res) => {
//   const url = "http://www.dell-lee.com/typescript/demo.html";
//   const filePath = path.resolve(__dirname, "../data/course.json");
//   const analyzer = WalkerAnalyzer.getInstance();
//   const crawler = new Crawler(url, filePath, analyzer);
//   res.json(getResponseData(true));
// });

// router.get("/showdata", checkLogin, (req, res) => {
//   try {
//     const position = path.resolve(__dirname, "../data/course.json");
//     const result = fs.readFileSync(position, "utf-8");
//     res.json(getResponseData(JSON.parse(result)));
//   } catch (e) {
//     res.json(getResponseData(false, "No data yet!"));
//   }
// });

export default router;
